import VueRouter from 'vue-router'

// const requireAll = requireContext => requireContext.keys().map(requireContext)
let route = []
const context = require.context('./', true, /\.js$/)
context.keys().forEach((key) => {
  const module = context(key).default
  if (key !== 'index.js' && Object.prototype.toString.apply(module) === '[object Array]') {
    route = route.concat(module)
  }
})
const router = new VueRouter({ route })
router.beforeEach((to, from, next) => {
  router.app.$Message.loading('页面加载中...', 0)
  next()
})
router.afterEach(() => {
  router.app.$Message.destroy()
})
export default router
